package ModelLayer;
import java.util.ArrayList;


/**
 * Write a description of class ItemCategory here.
 * 
 * @author (your name) 
 * @version (a version number or a date)
 */
public class ItemCategory
{
    // instance variables - replace the example below with your own
    private long id;
    private String name;
    private ArrayList<RentItem> rentItemList = new ArrayList<RentItem>();
    private ArrayList<SellItem> sellItemList = new ArrayList<SellItem>();
    
    public ItemCategory(long _id, String _name)
    {
        id = _id;
        name = _name;
    }
    
    /**
     * Rent Item Methods Part
     * 
     */
    
    public RentItem getRentItem(long _id)
    {
        RentItem ri = new RentItem();
        ri = null;
        for (int i=0; i<rentItemList.size(); i++)
        {
            if (rentItemList.get(i).getId() == _id)
            { 
                ri = rentItemList.get(i);
                return ri;
            }
            else
                ri = null;
        }
        
        return ri;
    }
    
    public void createRentItem(RentItem _item)
    {
        rentItemList.add(_item);
    }
    
    public void updateRentItem(RentItem _item)
    {
        getRentItem(_item.getId()).setId(_item.getId());
        getRentItem(_item.getId()).setName(_item.getName());
        getRentItem(_item.getId()).setLocation(_item.getLocation());
        getRentItem(_item.getId()).setWeeklyRate(_item.getWeeklyRate());        
    }
    
    public void removeRentItem(long _id)
    {
        for(int i=0; i<rentItemList.size(); i++)
        {
            if(rentItemList.get(i).getId() == _id)
            {
                rentItemList.remove(i);
            }
        }
    }
    
    public ArrayList<RentItem> listAllRentItems()
    {
        return rentItemList;
    }
    
    /**
     * Sell Item Methods Part
     * 
     */
    
    public SellItem getSellItem(long _id)
    {
        SellItem si = new SellItem();
        si = null;
        for (int i=0; i<sellItemList.size(); i++)
        {
            if (sellItemList.get(i).getId() == _id)
            { 
                si = sellItemList.get(i);
                return si;
            }
            else
                si = null;
        }
        
        return si;
    }
    
    public void createSellItem(SellItem _item)
    {
        sellItemList.add(_item);
    }
    
    public void updateSellItem(SellItem _item)
    {
        getSellItem(_item.getId()).setId(_item.getId());
        getSellItem(_item.getId()).setName(_item.getName());
        getSellItem(_item.getId()).setLocation(_item.getLocation());
        getSellItem(_item.getId()).setStock(_item.getStock());
        getSellItem(_item.getId()).setPrice(_item.getPrice());
    }
    
    public void removeSellItem(long _id)
    {
        for(int i=0; i<sellItemList.size(); i++)
        {
            if(sellItemList.get(i).getId() == _id)
            {
                sellItemList.remove(i);
            }
        }
    }
    
    public ArrayList<SellItem> listAllSellItems()
    {
        return sellItemList;
    }
    
    public long getId()
    {
        return id;
    }
    
    public String getName()
    {
        return name;
    }
    
    public void setId(long newid)
    {
        id = newid;
    }
    
    public void setName(String newname)
    {
        name = newname;
    }
}
